package com.example.alltestapplication

import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.example.alltestapplication.ui.theme.AllTestApplicationTheme

class WifiSettingsActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            AllTestApplicationTheme {
                Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
                    WifiSettingsScreen(modifier = Modifier.padding(innerPadding))
                }
            }
        }
    }

    private fun openWifiSettings() {
        val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            Intent(Settings.ACTION_WIFI_SETTINGS)
        } else {
            Intent(Settings.ACTION_WIRELESS_SETTINGS)
        }
        startActivity(intent)
    }

    @Composable
    fun WifiSettingsScreen(modifier: Modifier = Modifier) {
        Button(onClick = { openWifiSettings() }, modifier = modifier) {
            Text(text = "Open WiFi Settings")
        }
    }

    @Preview
    @Composable
    fun PreviewWifiSettingsScreen() {
        WifiSettingsScreen()
    }
}
